import { merge } from "lodash-es";
import { mapStore } from "../../utils/store";
import { $http } from "../../boot/http";
export default merge(
  {
    namespaced: true,
    state: {},
    mutations: {},
    getters: {},
    actions: {
      // 转让/撤销订单
      async sellOrder({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.order_sell",
            loading: async () => {
              const { data } = await $http.post("m/mfc/api/order/sell", params);
            }
          },
          {
            root: true
          }
        );
      },
      // 查看自己订单详情
      async orderDetail({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.order_sell",
            loading: async () => {
              const { data } = await $http.get("m/mfc/api/order/info", params);
              console.log(data);
              return data;
            }
          },
          {
            root: true
          }
        );
      },
      // 获取但单币种余额
      async coinBalance({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.coin_balance",
            loading: async () => {
              const { data } = await $http.get(
                "m/mfc/api/user/coin_balance",
                params
              );
              console.log(data);
              return data;
            }
          },
          {
            root: true
          }
        );
      },
      // 获取邀请码
      generateInvitation() {
        return $http.get("/api/v1/invitation");
      },
      // 获取站内信息未读数量
      async noticeNum({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "shop.notice_num",
            loading: async () => {
              const { data } = await $http.get("m/mfc/api/notice/num", params);
              console.log(data);
              return data.num;
            }
          },
          {
            root: true
          }
        );
      },
      // 修改会员信息
      async editUser({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "my.user_edit",
            loading: async () => {
              const { data } = await $http.post("m/mfc/api/user/edit", params);
              console.log(data);
              return data;
            }
          },
          {
            root: true
          }
        );
      },
      // 提取收益
      async extractReward({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "my.reward_extract",
            loading: async () => {
              const { data } = await $http.post(
                "m/mfc/api/reward/extract",
                params
              );
            }
          },
          {
            root: true
          }
        );
      },
      // 获取AB区数据
      async extractAb({ dispatch }) {
        return dispatch(
          "toggleLoading",
          {
            key: "my.ab_extract",
            loading: async () => {
              const { data } = await $http.get("m/mfc/api/user/dep_total");
              return data;
            }
          },
          {
            root: true
          }
        );
      },
      // 获取申诉类型 m/user/api/appeal/types
      async appealType({ dispatch }) {
        return dispatch(
          "toggleLoading",
          {
            key: "my.appeal_types",
            loading: async () => {
              const { data } = await $http.get("m/user/api/appeal/types");
              return data;
            }
          },
          {
            root: true
          }
        );
      },
      // 提交工单 /m/user/api/appeal/add
      async appealAdd({ dispatch }, params) {
        return dispatch(
          "toggleLoading",
          {
            key: "my.appeal_add",
            loading: async () => {
              const { data } = await $http.post(
                "m/user/api/appeal/add",
                params
              );
            }
          },
          {
            root: true
          }
        );
      },
    }
  },
  // 获取订单列表
  mapStore("orderList", {
    url: "m/mfc/api/order/index",
    options: {
      actionOptions: {
        commitType: "infinite"
      }
    },
    loadingKey: "mf.my.order_list"
  }),
  // 获取我的团队列表 m/mfc/api/user/team
  mapStore("userTeam", {
    url: "m/mfc/api/user/team",
    options: {
      actionOptions: {
        commitType: "infinite"
      }
    },
    loadingKey: "xhhx.shop.user_team"
  }),
  // 获取资金明细
  mapStore("logList", {
    url: "m/coin/api/v1/assets/log_list",
    options: {
      actionOptions: {
        commitType: "infinite"
      }
    },
    loadingKey: "mf.my.log_list"
  }),
  // 站内信息列表
  mapStore("noticeList", {
    url: "m/mfc/api/notice/index",
    options: {
      actionOptions: {
        commitType: "infinite"
      }
    },
    loadingKey: "xhhx.shop.notice_list"
  }),
  // 获取用户拓展信息
  mapStore("userInfo", {
    url: "m/mfc/api/user/info",
    getter: false,
    options: {
      actionOptions: {
        commitType: "data"
      }
    },
    loadingKey: "my.user_info"
  }),
  // 获取用户团队信息
  mapStore("teamInfo", {
    url: "m/mfc/api/user/team_total",
    options: {
      actionOptions: {
        commitType: "data"
      }
    },
    loadingKey: "my.user_info"
  }),
  // 获取奖励列表
  mapStore("rewardList", {
    url: "m/mfc/api/reward/index",
    options: {
      actionOptions: {
        commitType: "infinite"
      }
    },
    loadingKey: "my.reward_list"
  }),
  // 获取提现列表
  mapStore("withdrawList", {
    url: 'm/coin/api/v1/withdraw_list',
    options: {
      actionOptions: {
        commitType: "infinite"
      }
    },
    loadingKey: "my.withdraw_list"
  })
);
